<template>
  <div class="app-container">
    <div class="contentDiv">
      <el-tabs v-model="activeCode" @tab-click="tabClick">
        <el-tab-pane v-for="item in tabList" :key="item.route" :label="item.templateClassificationName" :name="item.templateClassificationCode" :data-route="item.route" />
      </el-tabs>
      <div class="tx-r" style="margin-bottom:10px">
        <el-button v-permiss="['60303020']" size="small" class="filter-item" type="primary" round :disabled="!activeCode" @click="handleAdd">新增</el-button>
      </div>
      <el-table :key="tableKey" v-loading="listLoading" :data="tableData" fit highlight-current-row style="width: 100%;" size="small" row-key="id">
        <el-empty slot="empty" :image-size="120" description="暂无数据" />
        <el-table-column label="模板分类" align="left" width="120">
          <template slot-scope="{row}">
            <span>{{ row.templateClassificationName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="模板代码" align="center" min-width="120">
          <template slot-scope="{row}">
            <span>{{ row.templateCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="模板名称" align="center" min-width="120">
          <template slot-scope="{row}">
            <span>{{ row.templateName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="模板类型" align="center" min-width="120">
          <template slot-scope="{row}">
            <span>{{ row.templateType == 0 ? '系统' : row.templateType == 1 ? '公司' : '个人' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="模板说明" align="center" min-width="120">
          <template slot-scope="{row}">
            <span>{{ row.remarks }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否默认" align="center">
          <template slot-scope="{row}">
            <span>{{ row.isDefault==1?'是':'否' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否启用" align="center">
          <template slot-scope="{row}">
            <span>{{ row.isDisable==0?'是':'否' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="{row}">
            <el-button v-permiss="['60303030']" type="text" size="small" @click="handleCompile(row.id)">编辑</el-button>
            <el-button v-permiss="['60303060']" type="text" size="small" @click="handleDel(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { getRptTemplate, getTemplateClassification, delRptByHeaderId } from '@/api/basedata'
export default {
  name: 'RptTemplate',
  data() {
    return {
      tabList: [],
      tableKey: 0,
      tableData: [],
      treeData: [],
      activeCode: '',
      activeRoute: 'rpt/purchase',
      defaultProps: {
        children: 'children',
        label: 'templateClassificationName'
      },
      handleObj: {},
      selectIdArr: [],
      total: 0,
      listLoading: true,
      parentId: '',
      dialogVisible: false,
      showModal: false,
      dialogStatus: ''
    }
  },
  created() {
    this.getTabList()
  },
  methods: {
    getTabList() {
      getTemplateClassification('report').then((res) => {
        this.tabList = res.data.data
        if (this.tabList.length > 0) {
          this.activeCode = this.tabList[0].templateClassificationCode
          this.getList()
        }
      })
    },
    tabClick(e) {
      this.activeCode = e.name
      this.getList()
    },
    getList() {
      this.listLoading = true
      getRptTemplate({ templateClassificationCode: this.activeCode }).then(res => {
        this.listLoading = false
        this.tableData = res.data.data
      }).catch(() => {
        this.listLoading = false
      })
    },
    handleAdd() {
      this.$router.push('/set/template/rptAdd?code=' + this.activeCode)
    },
    handleCompile(id) {
      this.$router.push('/set/template/rptModify?id=' + id + '&code=' + this.activeCode)
    },
    handleDel(id) {
      this.$confirm('确定删除？', '提示', {
        confirmButtonText: '确定',
        closeOnClickModal: false,
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delRptByHeaderId(id).then(res => {
          if (res.data.errorCode === '0') {
            this.getList()
            this.$message.success(res.data.msg)
          }
        })
      })
    }
  }
}
</script>
<style scoped>
.curTit {
  font-size: 14px;
  margin-bottom: 10px;
}

.main {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0 10px;
  padding-left: 180px;
}

.leftTree {
  width: 160px;
  height: 100%;
  background-color: #fff;
  position: absolute;
  top: 20px;
  left: 20px;
  border: 1px #eee solid;
}

.tableDiv {
  width: 100%;
}
</style>
